﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using $myprojectname$.Infrastructure.Abstract.Providers;
using System.Web.Security;
using System.Web;

namespace $myprojectname$.Infrastructure.Providers
{
    /// <summary>
    /// Authentication provider implementation.
    /// </summary>
    public class AuthenticationProvider : IAuthenticationProvider
    {
        public bool Authenticate(string username, string password)
        {
            bool isAuthenticated = false;
            
            if (username == "admin" && password == "admin")
            {
                FormsAuthentication.SetAuthCookie(username, false);
                isAuthenticated = true;
            }

            return isAuthenticated;
        }

        public void SignOut()
        {
            FormsAuthentication.SignOut();

            // Clear authentication cookie.
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
            authCookie.Expires = DateTime.Now.AddYears(-1);
            HttpContext.Current.Response.Cookies.Add(authCookie);

            HttpContext.Current.Session.Clear();
        }
    }
}